<?php
namespace app\mobile\controller;

use think\Controller;

class Policy extends Controller
{
	public function policy_list_view()
	{
		if (!session('user_id','','mobile')){
			$this->assign('iflogin','never');
		}else {
			$this->assign('iflogin','has');
		}
		return $this->fetch('policy_list');
	}
	
	public function policy_list()
	{
		$result = array('err'=>'1','content' => '','data'=>array());
		$keyword = trim(input('get.keyword'));
		$pageSize = trim(input('get.pageSize'));
		$model = model('Policy');
		$policy_list = $model->getPolicyList(session('user_id','','mobile'),session('role','','mobile'),$keyword,$pageSize);
		$result['data'] = json_encode($policy_list);
		return $result;
	}
	
	public function policy()
	{
		$policy_id = trim(input('get.policy_id'));
		$policy = db('policy')->where('id',$policy_id)->find();
		$this->assign('policy',$policy);$policy_info = db('policy')->where('id',$policy_id)->find();
    	$policy_info['attachments'] = json_decode($policy_info['attachments'],true);
    	$policy_info['createdwho'] = db('user')->where('id',$policy_info['createdwho'])->value('user_name');
    	$this->assign('policy',$policy_info);
		return $this->fetch('policy');
	}
	
	public function download_attachment()
	{
		$file_path = trim(input('file_path'));
		if ($file_path == ''){
			return false;
		}
		$file_path = ROOT_PATH.'Uploads'.DS.'policy'.DS.$file_path;
		$resource = new Resource();
		$resource->download($file_path);
	}
}